const app = getApp()
import { getMyJoinTeamMember, postQuitTeam } from '../../../../api/index'

Page({
  data: {
    teamId: '',
    members: []
  },
  async quitTeam () {
    try {
      const { confirm } = await wx.$pro.showModal({ title: '退出团队', content: '确定要退出当前团队吗？' })
      if (confirm) {
        await postQuitTeam({ teamId: this.data.teamId })
        wx.showToast({ title: '退出成功！', icon: 'none' })
        wx.$nav.navigateBack()
      }
    } catch (err) {
      wx.showToast({ title: err.message || err.ResultSet.errors, icon: 'none' })
    }
  },
  async getList () {
    try {
      const { ResultSet } = await getMyJoinTeamMember({ teamId: this.data.teamId })
      this.setData({ members: ResultSet.userData.data })
    } catch (err) {
      wx.showToast({ title: err.message || err.ResultSet.errors, icon: 'none' })
    }
  },
  onLoad ({ id }) {
    this.setData({ teamId: id })
    this.getList()
  }
})